package davidlauzon.activerecord.models;

import java.sql.SQLException;
import java.util.Map;

import davidlauzon.activerecord.ActiveRecord;
import davidlauzon.activerecord.manager.SelectManager;
import davidlauzon.activerecord.nodes.Table;
import davidlauzon.activerecord.nodes.field.Field;
import davidlauzon.activerecord.nodes.field.FloatField;
import davidlauzon.activerecord.nodes.field.IntegerField;
import davidlauzon.activerecord.nodes.field.StringField;


public class Product extends ActiveRecord
{
    public static final Field ID        = new IntegerField("id", true);
    public static final Field NAME      = new StringField("name", false);
    public static final Field PRICE     = new FloatField("price", false);
    public static final Field PERSON_ID = new IntegerField("person_id", false);
    
    
    public static final Field[] FIELDS = {ID,NAME,PRICE,PERSON_ID};
    
    @Override public Table        getTable()          { return DB.PRODUCTS_TABLE; }
    @Override public Field[]      getFields()         { return FIELDS; }
    public ActiveRecord getStaticInstance() { return _static_instance; }
    
    static private Class __klass = Product.class;
    static public Product build( Map<Field, Object> attributes)                              { return (Product)build(__klass, attributes); }
    static public Product create(Map<Field, Object> attributes) throws SQLException          { return (Product)create(__klass, attributes); }
    static public boolean update(long id, Map<Field, Object> attributes) throws SQLException { return update(__klass, id, attributes); }
    static public boolean delete(long id) throws SQLException                                { return delete(__klass, id); }
    static public SelectManager find(String condition) throws SQLException                   { return find(__klass,  condition); }
    
    // MUST BE INSTANCIATED AFTER ALL OTHER VARIABLES
    static protected final Product _static_instance = new Product();
}
